#pragma once

#include <linux/kconfig.h>
#include <linux/spinlock.h>
#include <linux/thread_info.h>

#include <linux/sched/sched_types.h>
#include <linux/sched/wake_q.h>
#include <linux/refcount_types.h>
#include <linux/cpumask_types.h>

struct sched_class;
struct nsproxy;
struct pid;

struct task_struct
{
    struct thread_info thread_info;

    const struct sched_class *sched_class;
    void *stack;
    struct sched_entity se;
    struct sched_rt_entity rt;
    struct sched_dl_entity dl;
    /* Protection of the PI data structures: */
    raw_spinlock_t pi_lock;
    struct wake_q_node wake_q;

    struct nsproxy *nsproxy;

    /* PID/PID hash table linkage. */
#ifdef CONFIG_PID
    struct pid *thread_pid;
#endif

    refcount_t rcu_users;
    refcount_t usage;

    unsigned int __state;
    unsigned int saved_state;
    unsigned int flags;
    short prio;
    short normal_prio;
    short static_prio;
    short policy;
    unsigned char rt_priority;

    unsigned char on_rq;
    unsigned char on_cpu;

    char name[16];

    struct
    {
        unsigned char is_percpu : 1;
        unsigned char should_park : 1;
        unsigned char should_stop : 1;
    } kthread;

    int exit_signal;

    unsigned int nr_cpus_allowed;
    unsigned short migration_disabled;
#ifdef CONFIG_SMP
    unsigned short recent_used_cpu;
    unsigned short wake_cpu;
    unsigned short migration_flags;
    cpumask_t cpus_mask;
    const cpumask_t *cpus_ptr;
#endif

    /* PI waiters blocked on a rt_mutex held by this task: */
    struct rb_root_cached pi_waiters;
    /* Updated under owner's pi_lock and rq lock */
    struct task_struct *pi_top_task;
    /* Deadlock detection and priority inheritance handling: */
    struct rt_mutex_waiter *pi_blocked_on;

    struct list_head tasks;

    void *filedesc;

    /* Context switch counts: */
    unsigned long nvcsw;
    unsigned long nivcsw;

    /* PF_KTHREAD | PF_IO_WORKER */
    void *worker_private;
};
